﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using AdminModule.Filter;
using System.ComponentModel;
using System.Linq;

namespace AdminModule.IndexMarkServiceReference
{
    public partial class FilterItem
    {
        private List<Condition> conditions = new List<Condition>();
        // Отображать операторы только для строковых типов
        private bool isString = false;

        public bool IsString
        {
            get
            {
                return isString;
            }
            set
            {
                isString = value;
                RaisePropertyChanged("Conditions");
            }
        }

        public FilterItem(System.Collections.IEnumerable FilterAttributes)
        {
            conditions.Add(new Condition { ConditionName = "=", ConditionToolTip = "Равно", ConditionType = ConditionTypes.Equal });
            conditions.Add(new Condition { ConditionName = "<", ConditionToolTip = "Меньше", ConditionType = ConditionTypes.LessThen });
            conditions.Add(new Condition { ConditionName = ">", ConditionToolTip = "Больше", ConditionType = ConditionTypes.GreaterThen });
            conditions.Add(new Condition { ConditionName = "<=", ConditionToolTip = "Меньше или равно", ConditionType = ConditionTypes.LessOrEqualThen });
            conditions.Add(new Condition { ConditionName = ">=", ConditionToolTip = "Больше или равно", ConditionType = ConditionTypes.GreaterOrEqualThen });
            conditions.Add(new Condition { ConditionName = "<>", ConditionToolTip = "Не равно", ConditionType = ConditionTypes.NotEqual });
            conditions.Add(new Condition { TypeIsString = true, ConditionName = "Вкл.", ConditionToolTip = "Включает", ConditionType = ConditionTypes.Contains });
            conditions.Add(new Condition { TypeIsString = true, ConditionName = "Искл.", ConditionToolTip = "Исключает", ConditionType = ConditionTypes.NotContains });

            foreach (object attribute in FilterAttributes)
            {
                this._Attributes.Add(attribute);
            }
        }

        private List<object> _Attributes = new List<object>();
        public List<object> Attributes
        {
            get { return _Attributes; }
            set { _Attributes = value; }
        }

        public IEnumerable<Condition> Conditions
        {
            get
            {
                if (isString)
                    return conditions.Where(x => x.TypeIsString == true);
                else
                    return conditions.Where(x => x.TypeIsString == false);
            }
        }
    }
}
